--[[	$Id: moveFrame.lua 2441 2011-12-19 10:55:23Z sdkyron@gmail.com $	]]

local _, caelCore = ...

caelCore.move = caelCore.createModule("Frame Mover")

local frames = {
	CharacterFrame, FriendsFrame, HelpFrame, InterfaceOptionsFrame,
	PVPFrame, QuestLogFrame, SpellBookFrame, VideoOptionsFrame
}

local lodFrames = {
	["Blizzard_AchievementUI"] = {
		"AchievementFrame"
	},
	["Blizzard_AuctionUI"] = {
		"AuctionFrame"
	},
	["Blizzard_GuildUI"] = {
		"GuildFrame"
	},
	["Blizzard_TalentUI"] = {
		"PlayerTalentFrame"
	}
}

for _, v in ipairs(frames) do
	v:EnableMouse(true)
	v:SetMovable(true)
	v:SetUserPlaced(false)
	v:SetClampedToScreen(true)
	v:RegisterForDrag("LeftButton")
	v:SetScript("OnDragStart", function(self) self:StartMoving() end)
	v:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
end

caelCore.move:RegisterEvent("ADDON_LOADED")
caelCore.move:SetScript("OnEvent", function(self, event, addonLoaded)
	if lodFrames[addonLoaded] then
		for k, v in pairs(lodFrames[addonLoaded]) do
			_G[v]:EnableMouse(true)
			_G[v]:SetMovable(true)
			_G[v]:SetUserPlaced(false)
			_G[v]:SetClampedToScreen(true)
			_G[v]:RegisterForDrag("LeftButton")
			_G[v]:SetScript("OnDragStart", function(self) self:StartMoving() end)
			_G[v]:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
		end
	end
end)